<?php
function overHole($mt_id,$rd_id,$pl_id){
	$sql = "SELECT count(*) FROM player_score 
            WHERE sc_pl_id = '".$pl_id."' AND sc_rd_id = '".$rd_id."' AND sc_mt_id = '".$mt_id."' AND sc_sts = '' ";    
    $res = mysql_query($sql);
    $row = mysql_fetch_array($res);
    return $row[0];
}

//读取新新贝利亚差点
function nnp_hdcp($mt_id,$rd_id,$pl_id){
	global $selected_hole;
	if (!empty($selected_hole)){
		$sql = "SELECT sum(sc_score) FROM player_score 
	            WHERE sc_pl_id = '".$pl_id."' AND sc_ho_id NOT IN(".$selected_hole.") AND sc_rd_id = '".$rd_id."' AND sc_mt_id = '".$mt_id."' AND sc_sts = '' ";
	    $res = mysql_query($sql);
	    $row = mysql_fetch_array($res);
	    $hdcp = ($row[0]*1.5-72)*0.8;
	}
	return $hdcp;
}

//新新贝利亚总杆
function nnp_total($mt_id,$rd_id,$pl_id){
	$sql = "SELECT sum(if(sc_score>(sc_par*2-1), (sc_par*2-1),sc_score) ) FROM player_score  
            WHERE sc_pl_id = '".$pl_id."' AND sc_rd_id = '".$rd_id."' AND sc_mt_id = '".$mt_id."' AND sc_sts = ''";
    $res = mysql_query($sql);
    $row = mysql_fetch_array($res);
    return $row[0];
}


//重新计算排名
function rankSummary($gp_point){
	global $net,$totalscore,$inscore,$sixscore,$threescore,$score;
	if (!empty($gp_point)){
	    $k=0;
	    foreach ($gp_point as $i => $n){
	        $arrid[$k] = $i;
	        $k++;
	    }
	    $len = count($arrid);
	    for ($i=0;$i<$len;$i++) {
	        for ($j=$i+1;$j<$len;$j++) {
	            if ($gp_point[$arrid[$i]] < $gp_point[$arrid[$j]]){                         //积分比较
	                $temp = $arrid[$j];
	                $arrid[$j] = $arrid[$i];
	                $arrid[$i] = $temp;
	            } else {
	                if ($gp_point[$arrid[$i]] == $gp_point[$arrid[$j]]){
	                    if ($net[$arrid[$i]] > $net[$arrid[$j]]){                                //差点比较
	                        $temp = $arrid[$j];
	                        $arrid[$j] = $arrid[$i];
	                        $arrid[$i] = $temp;
	                    } else {
	                        if ($net[$arrid[$i]] == $net[$arrid[$j]]){
	                            if ($totalscore[$arrid[$i]] > $totalscore[$arrid[$j]]){              //18洞总杆成绩和比较
	                                $temp = $arrid[$j];
	                                $arrid[$j] = $arrid[$i];
	                                $arrid[$i] = $temp;
	                            } else {
	                                if ($totalscore[$arrid[$i]] == $totalscore[$arrid[$j]]){
	                                    if ($inscore[$arrid[$i]] > $inscore[$arrid[$j]]){                 //后九洞成绩和比较
	                                        $temp = $arrid[$j];
	                                        $arrid[$j] = $arrid[$i];
	                                        $arrid[$i] = $temp;
	                                    } else {
	                                        if ($inscore[$arrid[$i]] == $inscore[$arrid[$j]]){
	                                            if ($sixscore[$arrid[$i]] > $sixscore[$arrid[$j]]){           //后六洞成绩和比较
	                                                $temp = $arrid[$j];
	                                                $arrid[$j] = $arrid[$i];
	                                                $arrid[$i] = $temp;
	                                            } else {
	                                                if ($sixscore[$arrid[$i]] == $sixscore[$arrid[$j]]){  
	                                                    if ($threescore[$arrid[$i]] > $threescore[$arrid[$j]]){   //后三洞成绩和比较
	                                                        $temp = $arrid[$j];
	                                                        $arrid[$j] = $arrid[$i];
	                                                        $arrid[$i] = $temp;
	                                                    } else {
	                                                        if ($threescore[$arrid[$i]] == $threescore[$arrid[$j]]){
	                                                            for($r=18; $r>=1; $r--){                              //18洞逐洞比较
	                                                                if ($score[$arrid[$i]][$r] > $score[$arrid[$j]][$r]){
	                                                                    $temp = $arrid[$j];
	                                                                    $arrid[$j] = $arrid[$i];
	                                                                    $arrid[$i] = $temp;
	                                                                    break;
	                                                                } 
	                                                            }
	                                                        }
	                                                    }
	                                                }
	                                            }
	                                        }
	                                    }
	                                }
	                            }
	                        }
	                    }
	                }
	            }
	        }
	    }

	    foreach ($arrid as $x => $y){
	        $rank[$y] = $y;
	    }
	}
	return $rank;
}








function arrayContact($arr1,$arr2){
	foreach ($arr1 as $key => $val){
		$new_arr[$key] = $val;
	}

	foreach ($arr2 as $key => $val){
		$new_arr[$key] = $val;
	}
	return $new_arr;
}

function scoreClass($topar,$score){
  if (!empty($score)){
    if ($topar<-1){
      $class = 'eagle';
    } elseif ($topar==-1){
      $class = 'birdie';
    } elseif ($topar==0){
      $class = 'par';
    } elseif ($topar==1){
      $class = 'bogey';
    } elseif ($topar>1){
      $class = 'db_bogey';
    } else {
      $class = 'par';
    }
  } else {
    $class = 'par';
  }
  return $class;
}


function netclass($net){
  if ($net==1){
    $style = 'style="background:#004080 !important;color:#FFFFFF !important;font:bold 14px Arail"';
  } elseif ($net==2){
    $style = 'style="background:#000000 !important;color:#fff !important;font:bold 14px Arail"';
  } else {
    $style = 'style="color:#000 !important;font:bold 14px Arail"';
  }
  return $style;
}
?>